//boolean
let isDone: boolean = false
// number
let age: number = 21
// number二进制
let binaryNum: number = 0b0101
// 字符串
let firstName: string = 'light'
// 模版字符串
let hey: string = `Hey,${firstName},age is ${age}`
// 未定义和空类型
let u: undefined = undefined
let n: null = null
//  undefined 和 null 是所有类型的子类型
// undefined类型可以赋值给number类型
let num: number = undefined
 
// any类型 大而全 任意类型
let notSure: any = 112233 //
notSure = "maybe is string"
notSure = true
//any也可以定义属性、函数方法，返回的类型也是any,IDE不会提示方法
notSure.namefor 
notSure.getName()

//联合类型 小而精准
let numberorstirng: number | string = 123 
numberorstirng = '123'
//会报错 Type 'true' is not assignable to type 'string | number'
//numberorstirng=true 


//数组
let arrOfNumbers: number[] = [1, 2, 5, 4]
arrOfNumbers.push(5)
//Argument of type '"str"' is not assignable to parameter of type 'number'.
arrOfNumbers.push('str')

function test() {
    console.log(arguments)//类数组
    // let a:number[]=arguments //无法使用
}
// 元组，限制了数据类型的数组
let user: [string, number] = ['12', 1] 
user = ['s', 2]




//函数声明
function add3(x: number, y: number, z: number=10): number { 
    return x + y + z
}
function add(x: number, y: number, z?: number): number {
    if (typeof z === 'number') {
        return x + y + z
    } else {
        return x + y
    }

}
let rusult = add(1, 3, 5)


//函数表达式
const add2 = function (x: number, y: number, z?: number): number {
    if (typeof z === 'number') {
        return x + y + z
    } else {
        return x + y
    }

}
let rusult2 = add2(1, 3, 5)

let add_new:(x: number, y: number, z?: number)=>number=add

//类型推断
let str='123'
str=1123  //报错 Type '1123' is not assignable to type 'string'.

//